//
//  NSString+BMLSHA_1.m
//  24-加密
//
//  Created by GivenBmli on 16/8/16.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "NSString+BMLSHA_1.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (BMLSHA_1)
//    1.将字符串转换成C语言字符串
- (NSString *)stringWithSHA_1 {
    const char *cSing = [self UTF8String];
//    求长度
    CC_LONG len = (CC_LONG)strlen(cSing);
    
    unsigned char bytes[CC_SHA1_DIGEST_LENGTH];
    CC_SHA1(cSing,len,bytes);
    NSMutableString *finalSHA1 = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH];
    for (int i = 0; i< CC_SHA1_DIGEST_LENGTH; i++) {
        [finalSHA1 appendFormat:@"%02x",bytes[i]];
        
    }
    return finalSHA1;
}


@end
